package dto

import (
	"encoding/json"
	"tuowei.com/app/admin/models"
	"tuowei.com/common/dto"
	common "tuowei.com/common/models"
)

type SysQuestionBankInsertReq struct {
	Id               int    `json:"id" comment:"主键ID"`
	KnowledgePointId int    `json:"knowledge_point_id" comment:"知识点ID"`
	SubjectType      string `json:"subject_type" comment:"科目类型 大学英语/大学数学/大学语文" ` //vd:"$>0; msg:'题目类型不能为空 网课=1 题库=2'"
	//ExerciseType     string `json:"exercise_type" comment:"题目类型 1-单选题 2-多选题 3-判断题 4-应用题" vd:"@:len($)>0; msg:'请选择题目类型'"`
	Content string `json:"content" comment:"题目内容" vd:"@:len($)>0; msg:'题目内容不能为空'"`
	//Answer           interface{} `json:"answer" comment:"答案" vd:"@:len($)>0; msg:'题目答案不能为空'"`
	Score         float64     `json:"score"`
	Answer        interface{} `json:"answer" comment:"答案"`
	CorrectAnswer string      `json:"correct_answer" comment:"正确答案"`
	Analysis      string      `json:"analysis" gorm:"type:text;comment:题目解析"`
	Subject       string      `json:"subject" comment:"科目类型 大学英语/大学数学/大学语文"`
	common.ControlBy
}

func (s *SysQuestionBankInsertReq) Generate(model *models.SysQuestionBank) {
	//model.CourseId = s.CourseId
	model.SubjectType = s.SubjectType
	model.Subject = s.Subject
	//model.ExerciseType = s.ExerciseType
	model.CorrectAnswer = s.CorrectAnswer
	model.Content = s.Content
	if s.Answer != nil {
		byts, _ := json.Marshal(s.Answer)
		model.Answer = string(byts)
	}
	model.Score = s.Score
	model.Analysis = s.Analysis
	model.CreateBy = s.CreateBy
	model.Creator = s.Creator
}

func (s *SysQuestionBankInsertReq) GetId() interface{} {
	return s.Id
}

type SysQuestionBankGetPageReq struct {
	dto.Pagination `search:"-"`
	Content        string `form:"content" search:"type:contains;column:content;table:sys_question_bank" comment:"题目内容"`
	//ExerciseType   string `form:"exercise_type" search:"type:exact;column:exercise_type;table:sys_question_bank" comment:"题目类型"`
	SubjectType string `form:"subject_type" search:"type:exact;column:subject_type;table:sys_question_bank" comment:"科目类型"`
	Subject     string `form:"subject" search:"type:exact;column:subject;table:sys_question_bank" comment:"科目类型 大学英语/大学数学/大学语文"`
}

func (m *SysQuestionBankGetPageReq) GetNeedSearch() interface{} {
	return *m
}

type SysQuestionBankUpdateReq struct {
	Id          int    `json:"id" comment:"主键ID" vd:"$>0;msg:'更新ID不能为空'"`
	SubjectType string `json:"subject_type" comment:"科目类型" vd:"@:len($)>0; msg:'科目类型不能为空'"`
	//ExerciseType  string      `json:"exercise_type" comment:"题目类型" vd:"@:len($)>0; msg:'请选择题目类型'"`
	Content       string      `json:"content" comment:"题目内容"`
	Answer        interface{} `json:"answer" comment:"答案"`
	CorrectAnswer string      `json:"correct_answer" comment:"正确答案"`
	Analysis      string      `json:"analysis" gorm:"type:text;comment:题目解析"`
	Score         float64     `json:"score"`
	Subject       string      `json:"subject" gorm:"type:varchar(10);comment:科目类型 大学英语/大学数学/大学语文"`
	common.ControlBy
}

func (s *SysQuestionBankUpdateReq) Generate(model *models.SysQuestionBank) {
	if s.Id != 0 {
		model.Id = s.Id
	}
	model.SubjectType = s.SubjectType
	model.Subject = s.Subject
	model.CorrectAnswer = s.CorrectAnswer
	//model.ExerciseType = s.ExerciseType
	model.Content = s.Content
	byts, _ := json.Marshal(s.Answer)
	model.Answer = string(byts)
	model.Analysis = s.Analysis
	model.UpdateBy = s.UpdateBy
	model.Updater = s.Updater
	model.Score = s.Score
}

func (s *SysQuestionBankUpdateReq) GetId() interface{} {
	return s.Id
}

type SysQuestionBankById struct {
	dto.ObjectById
	common.ControlBy
}

type SaveSelectedQuestionBankReq struct {
	QuestionBankStr string `json:"question_bank_str"`
	ChapterId       int    `json:"chapter_id" comment:"子章节ID"`
	LinkType        int    `json:"link_type" comment:"关联ID link_type=1 关联ID为练习题主键ID =2关联ID为试卷主键ID" vd:"$>0; msg:'关联类型不能为空'"`
	LinkId          int    `json:"link_id" vd:"$>0; msg:'关联ID不能为空'"`
	//ParentChapterId int    `json:"parent_chapter_id" vd:"$>0; msg:'大章节ID不能为空'"`
}

func (s SaveSelectedQuestionBankReq) Generate(link *models.SysQuestionBankLink) {
	link.QuestionBankStr = s.QuestionBankStr
	link.LinkType = s.LinkType
	link.LinkId = s.LinkId
	link.ChapterId = s.ChapterId
}

type SysQuestionBankListByIDS struct {
	LinkId    int `json:"link_id" search:"type:exact;column:link_id;table:sys_question_bank_link" comment:"关联ID"`
	LinkType  int `json:"link_type" search:"type:exact;column:link_type;table:sys_question_bank_link" comment:"关联类型"`
	ChapterId int `json:"chapter_id" search:"type:exact;column:chapter_id;table:sys_question_bank_link" comment:"章节ID"`
}

func (m *SysQuestionBankListByIDS) GetNeedSearch() interface{} {
	return *m
}
